import Vue from 'vue'
import Router from 'vue-router'
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)
/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/

// 作为Main组件的子页面展示并且在左侧菜单显示的路由写constantRouterMap里
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', name: 'error_404', meta: { title: '404-页面不存在' }, component: () => import('@/views/error_page/404'), hidden: true },
  { path: '/403', name: 'error_403', meta: { title: '403-权限不足' }, component: () => import('@/views/error_page/403'), hidden: true },
  { path: '/500', name: 'error_500', meta: { title: '500-服务端错误' }, component: () => import('@/views/error_page/500'), hidden: true },
  {
    // 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherRouter里
    path: '/',
    name: 'otherRouter',
    redirect: '/dashboard/workplace',
    component: Layout,
    children: [{
      path: 'own',
      name: 'own_index',
      component: () => import('@/views/own/index.vue'),
      meta: { title: '个人中心' },
      hidden: true
    }],
    hidden: true
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard/workplace',
    name: 'Dashboard',
    meta: { title: 'Dashboard', icon: 'dashboard' },
    children: [{
      path: 'workplace',
      name: 'workplace',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台' }
    }, {
      path: 'analysis',
      name: 'analysis',
      component: () => import('@/views/dashboard/analysis'),
      meta: { title: '分析页' }
    }, {
      path: 'bulletinBoard',
      name: 'bulletinBoard',
      component: () => import('@/views/dashboard/bulletinBoard'),
      meta: { title: '公告' },
      hidden: false
    },
    {
      path: 'bulletinBoard/new_item',
      component: () => import('@/views/dashboard/components/createBulletinArticle'),
      name: 'newBulletinItem',
      meta: { title: '创建公告', noCache: true },
      hidden: true
    },
    {
      path: 'bulletinBoard/item/detail/:id',
      component: () => import('@/views/dashboard/components/bulletinItemDetail'),
      name: 'bulletinItemDetail',
      meta: { title: '公告详细', noCache: true },
      hidden: true
    },
    {
      path: 'bulletinBoard/item/:id',
      component: () => import('@/views/dashboard/components/editBulletinArticle'),
      name: 'editBulletinItem',
      meta: { title: '编辑公告', noCache: true },
      hidden: true
    },
    {
      path: 'notifications',
      name: 'notifications',
      component: () => import('@/views/dashboard/notifications'),
      meta: { title: '消息通知' },
      hidden: true
    }, {
      path: 'todo',
      name: 'todo',
      component: () => import('@/views/dashboard/todo'),
      meta: { title: '待办' },
      hidden: true
    }]
  },
  {
    path: '/company',
    component: Layout,
    redirect: '/company/all',
    name: 'Company',
    meta: { title: '客户管理', icon: 'player' },
    children: [
      {
        path: 'all',
        name: 'company',
        component: () => import('@/views/company/all'),
        meta: { title: '客户' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/company/companyDetail'),
        name: 'companyDetail',
        meta: { title: '公司详情', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/candidate',
    component: Layout,
    redirect: '/candidate/all',
    name: 'candidate_menu',
    meta: { title: '人才管理', icon: 'peoples' },
    children: [
      {
        path: 'all',
        name: 'candidate',
        component: () => import('@/views/candidate/all'),
        meta: { title: '人才' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/candidate/candidateDetail'),
        name: 'candidateDetail',
        meta: { title: '人才详情', noCache: true },
        hidden: true
      },
      {
        path: 'cv/todo/:id/',
        component: () => import('@/views/candidate/cvTodo'),
        name: 'cvTodo',
        meta: { title: '推荐待办', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/project',
    component: Layout,
    redirect: '/project/all',
    name: 'project_menu',
    meta: { title: '项目管理', icon: 'form' },
    children: [
      {
        path: 'all',
        name: 'project',
        component: () => import('@/views/project/all'),
        meta: { title: '项目' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/project/projectDetail'),
        name: 'projectDetail',
        meta: { title: '项目详情', noCache: true },
        hidden: true
      },
      {
        path: 'todo/:id/',
        component: () => import('@/views/project/projectTodo'),
        name: 'projectTodo',
        meta: { title: '项目待办', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/invoice',
    component: Layout,
    redirect: '/invoice/all',
    name: 'invoice_menu',
    meta: { title: '发票管理', icon: 'money' },
    children: [
      {
        path: 'all',
        name: 'invoice',
        component: () => import('@/views/invoice/all'),
        meta: { title: '发票' }
      },
      {
        path: 'bill',
        name: 'bill',
        component: () => import('@/views/invoice/bill'),
        meta: { title: '款项明细' }
      },
      {
        path: 'company_account',
        name: 'company_account',
        component: () => import('@/views/invoice/company_account'),
        meta: { title: '公司账号' }
      },
      {
        path: 'todo/:id/',
        component: () => import('@/views/invoice/invoiceTodo'),
        name: 'invoiceTodo',
        meta: { title: '发票待办', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/list',
    component: Layout,
    redirect: '/list/all',
    name: 'list_menu',
    meta: { title: 'list库', icon: 'documentation' },
    children: [
      {
        path: 'all',
        name: 'list',
        component: () => import('@/views/list/all'),
        meta: { title: 'list' }
      }
    ]
  },
  {
    path: '/sys_manage',
    component: Layout,
    redirect: 'noredirect',
    name: 'System_manage',
    meta: { title: '系统管理', icon: 'system', roles: ['menu-sys-mgmt'] },
    children: [
      {
        path: 'user',
        name: 'User_manage',
        component: () => import('@/views/oa_auth/user'),
        meta: { title: '用户管理', roles: ['menu-sys-user'] }
      },
      {
        path: 'department',
        name: 'Department_manage',
        component: () => import('@/views/oa_auth/department'),
        meta: { title: '部门管理', roles: ['menu-sys-department'] }
      },
      {
        path: 'rank',
        name: 'Rank_manage',
        component: () => import('@/views/oa_auth/rank'),
        meta: { title: '岗位管理', roles: ['menu-sys-rank'] }
      },
      {
        path: 'log',
        component: () => import('@/views/errorLog/index'),
        name: 'errorLog',
        meta: { title: 'errorLog', roles: ['errorLog'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
